﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using EntityModel;

namespace Business
{
    public class CustomerProductService : BusinessBase<CustomerProduct, UserModel>
    {
        public int ReservedProduct(CustomerProduct reservedPackaged, UserModel userAccess)
        {
            try
            {
                var packaged = this.retreiveHelper.GetOne<CustomerProduct>(userAccess, reservedPackaged.UserID, reservedPackaged.ProductCode);

                if (packaged != null)
                {
                    packaged.ReservedQty = reservedPackaged.ReservedQty;
                    packaged.NumberOfDay = reservedPackaged.NumberOfDay;
                    packaged.ReservedDate = reservedPackaged.ReservedDate;
                    packaged.UpdatedBy = userAccess.UserID;
                    packaged.UpdatedDate = DateTime.Now;

                    this.executeHelper.Update(packaged, userAccess);
                    return Variables.UPDATED;
                }
                else
                {
                    reservedPackaged.CreatedBy = userAccess.UserID;
                    reservedPackaged.CreatedDate = DateTime.Now;
                    this.executeHelper.Insert(reservedPackaged, userAccess);
                    return Variables.INSERTED;
                }
            }
            catch
            {
                return Variables.ERROR;
            }
        }
    }
}
